function refreshs(func, con) {
    api.addEventListener({
        name: 'scrolltobottom'
    }, function(ret, err) {
        $api.byId('refresh').style = "display:block";
        var token = {
            j: ++j
        }
        api.ajax({
            url: 'http://www.mk517.com/webApi/huaming_list.php',
            tag: 'refresh',
            method: 'post',
            dataType: 'json',
            "headers": {
                "Content-Type": "application/json"
            },
            data: {
                body: token
            }
        }, function(ret, err) {
            $api.byId('refresh').style = "display:none";
            func(con);

            if (j > 0) {
                api.addEventListener({
                    name: 'swipedown'
                }, function(ret, err) {
                    $api.byId('refresh').style = "display:block";
                    var body = {
                        j: --j
                    }
                    api.ajax({
                        url: 'http://www.mk517.com/webApi/huaming_list.php',
                        tag: 'refresh',
                        method: 'post',
                        dataType: 'json',
                        "headers": {
                            "Content-Type": "application/json"
                        },
                        data: {
                            body: body
                        }
                    }, function(ret, err) {
                        $api.byId('refresh').style = "display:none";
                        func(con);
                    });

                });
            }

        });

    });
}


/*
 *匿名点赞功能start
 */
window.niming_postLaud = function(i, tieid) {
    var token = $api.getStorage('token');
    if (token != '') {
        if ($api.getStorage('state')) {
            var token = $api.getStorage('token');
            var body = {
                token: token,
                tieid: tieid,
                sta: 1
            };
            cancelLaudAjax(body, i);
            $api.rmStorage('state');
        } else {
            var token = $api.getStorage('token');
            var body = {
                token: token,
                tieid: tieid,
                sta: 0
            }
            laudAjax(body, i);
        }
    } else {
        api.alert({
            msg: '您还没有登录，请先登录！',
        }, function(ret, err) {});

    }
};
function laudAjax(body, i) {
    api.ajax({
        url: 'http://www.mk517.com/webApi/huaming_like.php',
        method: 'post',
        dataType: 'json',
        "headers": {
            "Content-Type": "application/json"
        },
        data: {
            body: body
        }
    }, function(ret, err) {
        if (ret) {
            if (ret.state == 'true') {
                $api.setStorage('state', ret.state);
                var laud = 'laud' + i;
                $api.byId(laud).style.color = '#0000E3';
                $api.byId(laud).innerHTML = (ret.count < 0) ? 0 : ret.count;
            }
        } else {
            //alert(JSON.stringify(err));
        }
    });
}

function cancelLaudAjax(body, i) {
    api.ajax({
        url: 'http://www.mk517.com/webApi/huaming_like.php',
        method: 'post',
        dataType: 'json',
        "headers": {
            "Content-Type": "application/json"
        },
        data: {
            body: body
        }
    }, function(ret, err) {
        if (ret) {
            var laud = 'laud' + i;
            $api.byId(laud).style.color = '';
            $api.byId(laud).innerHTML = (ret.count < 0) ? 0 : ret.count;
        } else {
            //alert(JSON.stringify(err));
        }
    });

}
//帖子详情
window.openniming=function(uid,id){

  api.openFrame({
      name: 'nimingInfo',
      url: '../wumi/nimingInfo.html',
      rect: {
          x: 0,
          y: 0,
          w: 'auto',
          h: 'auto'
      },
      pageParam: {
          postinfo: id,
          uid: uid
      },
      allowEdit: true
  });
}
//匿名评论

window.postComment = function(uid,id) {
    api.prompt({
        title: '请输入您的评论：',
        buttons: ['确定', '取消']
    }, function(ret, err) {
        var index = ret.buttonIndex;
        var text = ret.text;
        var token = $api.getStorage('token');
        if (index == 1) {
            var body = {
                token: token,
                msg: text,
                tieid: id,
                id: uid,
                comm_id: 0,
                comm_uid: 0
            };
            api.ajax({
                url: 'http://www.mk517.com/webApi/huaming_addcomment.php',
                method: 'post',
                dataType: 'json',
                "headers": {
                    "Content-Type": "application/json"
                },
                data: {
                    body: body
                }
            }, function(ret, err) {
                if (ret) {
                    if (ret.info == "true") {
                        $api.byId('note').innerHTML = ret.content;
                        api.openFrame({
                            name: 'nimingInfo',
                            url: '../wumi/nimingInfo.html',
                            rect: {
                                x: 0,
                                y: 0,
                                w: 'auto',
                                h: 'auto'
                            },
                            pageParam: {
                                postinfo: id,
                                id: uid
                            },
                            allowEdit: true
                        });
                    } else {
                        api.alert({
                            msg: '评论失败，请重试！',
                        }, function(ret, err) {});

                    }
                    // alert(JSON.stringify(ret));
                } else {
                    //  alert(JSON.stringify(err));
                }
            });

        }
    });
};

moneyOfCount = 0;

function ajaxOfjifen() {
    var token = $api.getStorage('token');
    var body = {
        token: token
    }
    api.ajax({
        url: 'http://www.mk517.com/webApi/jifen.php',
        method: 'post',
        dataType: 'json',
        "headers": {
            "Content-Type": "application/json"
        },
        data: {
            body: body
        }
    }, function(ret, err) {
        if (ret) {
            moneyOfCount = ret.money;
            $api.setStorage('moneyOfCount', moneyOfCount);
            // alert( JSON.stringify( ret ) );
        } else {
            // alert( JSON.stringify( err ) );
        }
    });

}
//打赏
window.postMon = function(id,uid) {
        ajaxOfjifen();
        moneyOfCount = $api.getStorage('moneyOfCount');
        api.prompt({
            title: '剩余:' + moneyOfCount+ '客币',
            buttons: ['确定', '取消']
        }, function(ret, err) {
            if (ret) {
                var index = ret.buttonIndex;
                var text = ret.text;
                var token = $api.getStorage('token');
                if (index == 1) {
                    var body = {
                        token: token,
                        tieid: id,
                        uid: uid,
                        text: text
                    };
                    api.ajax({
                        url: 'http://www.mk517.com/webApi/huaming_reward.php',
                        method: 'post',
                        dataType: 'json',
                        "headers": {
                            "Content-Type": "application/json"
                        },
                        data: {
                            body: body
                        }
                    }, function(ret, err) {
                      //alert(JSON.stringify(ret));
                        if (ret) {
                            if (ret.info == "true") {
                                api.alert({
                                    msg: '打赏成功！',
                                }, function(ret, err) {});
                                ajaxOfjifen();
                                $api.rmStorage('moneyOfCount');
                            } else if(ret.info='不予许给自己打赏'){
                              api.alert({
                                  msg: '您不能给自己打赏',
                              }, function(ret, err) {});

                            }else {
                              api.alert({
                                  msg: '您的积分不足！',
                              }, function(ret, err) {});

                            }
                            //alert( JSON.stringify( ret ) );
                        } else {
                            // alert( JSON.stringify( err ) );
                        }
                    });

                }
                //  alert( JSON.stringify( ret ) );
            } else {
                //  alert( JSON.stringify( err ) );
            }
        });
    }
    /*  打赏功能end */
